﻿using Fireball.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Xml.Linq; 
using System.ComponentModel; 

namespace FireballCoreTests
{
    
    
    /// <summary>
    ///This is a test class for StringCollectionTest and is intended
    ///to contain all StringCollectionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class StringCollectionTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Count
        ///</summary>
        [TestMethod()]
        public void CountTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test");
            target.Add("test");
            target.Add("test");
            Assert.IsTrue(target.Count == 4);
        }

   

        /// <summary>
        ///A test for Reverse
        ///</summary>
        [TestMethod()]
        public void ReverseTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test2");
            target.Add("test3");
            target.Add("test4");
            int index = 1;
            int count = 2; 
            target.Reverse(index, count);
            Assert.IsTrue(target[1] == "test3");
        }

        /// <summary>
        ///A test for RemoveRange
        ///</summary>
        [TestMethod()]
        public void RemoveRangeTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test2");
            target.Add("test3");
            target.Add("test4");
            int index = 1; 
            int count = 2;
            target.RemoveRange(index, count);
            Assert.IsFalse(target.Contains("test2"));
            Assert.IsFalse(target.Contains("test3"));
        }

        /// <summary>
        ///A test for RemoveDuplicates
        ///</summary>
        [TestMethod()]
        public void RemoveDuplicatesTest()
        {
            StringCollection target = new StringCollection();  
            target.RemoveDuplicates(); 
        }

        /// <summary>
        ///A test for RemoveAt
        ///</summary>
        [TestMethod()]
        public void RemoveAtTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test1");
            target.Add("test2");
            int index = 1;
            target.RemoveAt(index);
            Assert.IsFalse(target.Contains("test1"));
        }

        /// <summary>
        ///A test for RemoveAll
        ///</summary>
        [TestMethod()]
        public void RemoveAllTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test1");
            target.Add("test1");
            target.Add("test1");
            target.Add("test2");
            Predicate<string> match = new Predicate<string>(p => p == "test1");

            target.RemoveAll(match);
            Assert.IsFalse(target.Contains("test1"));
        }

        /// <summary>
        ///A test for Remove
        ///</summary>
        [TestMethod()]
        public void RemoveTest()
        {
            StringCollection target = new StringCollection(); 
            target.Add("test");
            target.Add("test1");
            target.Add("test2");
            string item = "test1"; 
            bool expected = true;
            bool actual;
            actual = target.Remove(item);
            Assert.AreEqual(expected, actual); 
        }

        /// <summary>
        ///A test for Move
        ///</summary>
        [TestMethod()]
        public void MoveTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test1");
            target.Add("test2");
            int index = 0;
            int newIndex = 2;
            target.Move(index, newIndex);
            Assert.IsTrue(target.IndexOf("test") == 2);
        }

        /// <summary>
        ///A test for LastIndexOf
        ///</summary>
        [TestMethod()]
        public void LastIndexOfTest2()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test1");
            target.Add("test2");
            target.Add("test3");

            string item = "test3";
            int index = 3; 
            int count = 1; 
            int expected = 3; 
            int actual;
            actual = target.LastIndexOf(item, index, count);
            Assert.AreEqual(expected, actual);            
        }

        /// <summary>
        ///A test for LastIndexOf
        ///</summary>
        [TestMethod()]
        public void LastIndexOfTest1()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test1");
            target.Add("test2");
            target.Add("test");
            string item = "test"; 
            int expected = 3;
            int actual;
            actual = target.LastIndexOf(item);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for InsertRange
        ///</summary>
        [TestMethod()]
        public void InsertRangeTest()
        {
            StringCollection target = new StringCollection();
            target.Add("asd");
            target.Add("asd");
            target.Add("asd");
            int index = 1;
            IEnumerable<string> collection = new string[] { "test", "test1" };
            target.InsertRange(index, collection);
            Assert.AreEqual(target.IndexOf("test"), 1);
            Assert.AreEqual(target.IndexOf("test1"), 2);
        }

        /// <summary>
        ///A test for Insert
        ///</summary>
        [TestMethod()]
        public void InsertTest()
        {
            StringCollection target = new StringCollection();
            target.Add("asd");
            target.Add("asd");
            target.Add("asd");
            int index = 1;
            string item = "test"; 
            target.Insert(index, item);
            Assert.AreEqual(target.IndexOf(item), 1);
        }

        /// <summary>
        ///A test for ImportXml
        ///</summary>
        [TestMethod()]
        public void ImportXmlTest()
        {
            StringCollection target = new StringCollection();
            XElement xCollection = new XElement("collection",
                new XElement("item", "test1"),
                new XElement("item", "test2"),
                new XElement("item", "test3"));
            target.ImportXml(xCollection);

            Assert.AreEqual(target.IndexOf("test1"), 0);
            Assert.AreEqual(target.IndexOf("test2"), 1);
            Assert.AreEqual(target.IndexOf("test3"), 2);
        }

        /// <summary>
        ///A test for IndexOf
        ///</summary>
        [TestMethod()]
        public void IndexOfTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test");
            target.Add("testA");
            target.Add("test");
            string item = "testA";
            int expected = 2;
            int actual;
            actual = target.IndexOf(item);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetRange
        ///</summary>
        [TestMethod()]
        public void GetRangeTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test1");
            target.Add("test2");
            target.Add("test3");
            int index = 1; 
            int count = 2;
            var expected = new string[]{ "test1", "test2" };
            var actual = target.GetRange(index, count).ToArray();
            Assert.IsTrue(expected[0] == actual[0]);
            Assert.IsTrue(expected[1] == actual[1]);
        } 
      

        /// <summary>
        ///A test for Exists
        ///</summary>
        [TestMethod()]
        public void ExistsTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            target.Add("test1");
            target.Add("test2");
            target.Add("test3");
            Predicate<string> match = delegate(string s)
            {
                return (s == "test2");
            };

            bool expected = true;
            bool actual;
            actual = target.Exists(match);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Contains
        ///</summary>
        [TestMethod()]
        public void ContainsTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            string item = "test";
            bool expected = true; 
            bool actual;
            actual = target.Contains(item);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Clone
        ///</summary>
        [TestMethod()]
        public void CloneTest()
        {
            StringCollection target = new StringCollection();
            target.Add("test");
            var actual = (StringCollection)target.Clone();
            Assert.AreEqual(target.Count, actual.Count);
        }

        /// <summary>
        ///A test for Clear
        ///</summary>
        [TestMethod()]
        public void ClearTest()
        {
            StringCollection target = new StringCollection();
            target.Clear();
            Assert.IsTrue(target.Count == 0);
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        [TestMethod()]
        public void AddTest()
        {
            StringCollection target = new StringCollection();
            string item = "newItem";
            target.Add(item);
            Assert.IsTrue(target.Contains(item));
        }
    }
}
